<template>
	<view class="savepadding p-content">

		<view class="item" style="padding: 20rpx 30rpx 0;margin-top: 20rpx;">

			<u-form :model="addbean" ref="uform" label-width="auto">

				<view style="height: 50rpx;display: flex;align-items: center;">
					<u-icon name="order" color="#1573FF" label="基本信息" label-color="#333333"></u-icon>
				</view>

				<u-form-item label="选择出租方" :required="true" borderBottom @click="selLessor">
					<u-input v-model="addbean.lessorName" inputAlign="right" placeholder="选择出租方" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

				<u-form-item label="选择客户" :required="true" borderBottom @click="selCustomer">
					<u-input v-model="addbean.customerName" inputAlign="right" placeholder="选择客户" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

				<u-form-item label="客户名称" borderBottom>
					<u-input v-model="addbean.customerName" inputAlign="right" disabled
						disabledColor="#ffffff" border="none" placeholder="选择客户自动获取"></u-input>
				</u-form-item>

				<u-form-item label="联系地址" borderBottom>
					<u-input v-model="addbean.customerAddr" inputAlign="right" disabled
						disabledColor="#ffffff" border="none" placeholder="选择客户自动获取">
					</u-input>
				</u-form-item>

				<u-form-item label="联系电话">
					<u-input v-model="addbean.customerTel" inputAlign="right" disabled
						disabledColor="#ffffff" border="none" placeholder="选择客户自动获取">
					</u-input>
				</u-form-item>

			</u-form>

		</view>

		<view class="item" style="padding: 20rpx 30rpx 0;">

			<u-form :model="addbean" ref="uform" label-width="auto">

				<view style="height: 50rpx;display: flex;align-items: center;">
					<u-icon name="order" color="#1573FF" label="车辆订单信息" label-color="#333333"></u-icon>
				</view>

				<u-form-item label="租赁类型" borderBottom>
					<u-input v-model="addbean.plan.rentTypeName" inputAlign="right" border="none" disabled
						disabledColor="#ffffff" placeholder=""></u-input>
				</u-form-item>

				<u-form-item label="品牌/车系/车型" :required="true" borderBottom @click="pickerShow(2)">
					<u-input v-model="addbean.plan.brandSeriesModel" inputAlign="right" placeholder="请选择品牌/车系/车型" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

				<u-form-item v-if="1==addbean.plan.rentType||3==addbean.plan.rentType||4==addbean.plan.rentType" label="保证金/元/台" :required="true" borderBottom>
					<u-input v-model="addbean.plan.cashDeposit" type="digit" inputAlign="right" placeholder="请输入" border="none"></u-input>
				</u-form-item>

				<u-form-item v-if="5==addbean.plan.rentType" label="首付款/元/台" :required="true" borderBottom>
					<u-input v-model="addbean.plan.downPayment" type="digit" inputAlign="right" placeholder="请输入" border="none"></u-input>
				</u-form-item>

				<u-form-item v-if="2==addbean.plan.rentType" label="整备费/元/台" :required="true" borderBottom>
					<u-input v-model="addbean.plan.servicingFee" type="digit" inputAlign="right" placeholder="请输入" border="none"></u-input>
				</u-form-item>

				<u-form-item v-if="6==addbean.plan.rentType" label="车辆总单价/元/台" :required="true" borderBottom>
					<u-input v-model="addbean.plan.totalPrice" type="digit" inputAlign="right" placeholder="请输入" border="none"></u-input>
				</u-form-item>

				<u-form-item v-if="1==addbean.plan.rentType||2==addbean.plan.rentType||3==addbean.plan.rentType||4==addbean.plan.rentType||5==addbean.plan.rentType" label="月租金/元/台" :required="true" borderBottom>
					<u-input v-model="addbean.plan.monthlyRent" type="digit" inputAlign="right" placeholder="请输入" border="none"></u-input>
				</u-form-item>

				<u-form-item v-if="2==addbean.plan.rentType||5==addbean.plan.rentType" label="尾款/元/台" borderBottom @click="addFinalFee">
					<u-input v-model="balancestr" inputAlign="right" placeholder="添加尾款" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

				<u-form-item v-if="5==addbean.plan.rentType" label="金融公司名称" borderBottom>
					<u-input v-model="addbean.plan.financeCompanyName" inputAlign="right" border="none" placeholder="请输入"></u-input>
				</u-form-item>

				<u-form-item v-if="1==addbean.plan.rentType||3==addbean.plan.rentType||4==addbean.plan.rentType" label="免费用车天数" borderBottom>
					<u-input v-model="addbean.plan.freeDays" type="number" inputAlign="right" border="none" placeholder="请输入">
					</u-input>
				</u-form-item>

				<!-- 新添加 -->
				<!-- 免费用车天数类型： -->
			<!-- 	<u-form-item v-if="1==addbean.plan.rentType||3==addbean.plan.rentType||4==addbean.plan.rentType" label="免费用车天数类型"  borderBottom @click="pickerShow(2)">
					<u-input v-model="addbean.plan.brandSeriesModel" inputAlign="right" placeholder="请选择" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item> -->

				<!-- 新添加 -->
				<!-- 是否需要增加免费用车天数： -->
				<!-- <u-form-item v-if="1==addbean.plan.rentType||3==addbean.plan.rentType||4==addbean.plan.rentType" label="是否需要增加免费用车天数" borderBottom>
					<u-input v-model="addbean.plan.freeDays" type="number" disabled inputAlign="right" border="none" placeholder="请输入">
					</u-input>
				</u-form-item> -->

				<u-form-item v-if="1==addbean.plan.rentType||3==addbean.plan.rentType||4==addbean.plan.rentType" label="服务费" borderBottom>
					<u-input v-model="addbean.plan.coverCharge" type="digit" inputAlign="right" border="none" placeholder="请输入">
					</u-input>
				</u-form-item>

				<u-form-item v-if="1==addbean.plan.rentType||2==addbean.plan.rentType||3==addbean.plan.rentType||4==addbean.plan.rentType" label="还款方式" :required="true" borderBottom @click="pickerShow(1)">
					<u-input v-model="addbean.plan.paymentMethodName" inputAlign="right" placeholder="请选择还款方式" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

				<view v-if="1==addbean.plan.rentType||2==addbean.plan.rentType||3==addbean.plan.rentType||4==addbean.plan.rentType" style="display: flex;flex-direction: column;">

					<u-form-item label="还款日" :required="true">
					</u-form-item>

					<view class="mradio" @click="addbean.orderCar.paymentDayType=1">
						<u-icon :color="1==addbean.orderCar.paymentDayType?'#1573FF':'#333'" :name="1==addbean.orderCar.paymentDayType?'checkmark-circle-fill':'checkmark-circle'" size="18"></u-icon>
						<text>还款日与交车日一致</text>
					</view>

					<view class="mradio" style="margin-top: 10rpx;" @click="addbean.orderCar.paymentDayType=2">
						<u-icon :color="2==addbean.orderCar.paymentDayType?'#1573FF':'#333'" :name="2==addbean.orderCar.paymentDayType?'checkmark-circle-fill':'checkmark-circle'" size="18"></u-icon>
						<text style="flex: 1;white-space: nowrap;">选择还款日</text>

						<view style="display: flex;align-items: center;" @click.stop="pickerShow(3)">
							<u-input v-model="payDayStr" inputAlign="right" placeholder="请选择还款日" disabled
								disabledColor="#ffffff" border="none"></u-input>
							<u-icon slot="right" name="arrow-right"></u-icon>
						</view>

					</view>
					<!-- 新添加 -->
					<!-- 租金生成方式： -->
					<!-- <u-form-item v-if="1==addbean.plan.rentType||2==addbean.plan.rentType||3==addbean.plan.rentType||4==addbean.plan.rentType" label="租金生成方式" :required="true" borderBottom @click="pickerShow(1)">
						<u-input v-model="addbean.plan.paymentMethodName" inputAlign="right" placeholder="请选择租金生成方式" disabled
							disabledColor="#ffffff" border="none"></u-input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item> -->

					<!-- 新添加 -->
					<!-- 首期租金 -->
					<!-- <u-form-item v-if="1==addbean.plan.rentType||3==addbean.plan.rentType||4==addbean.plan.rentType" label="首期租金" borderBottom>
						<u-input v-model="addbean.plan.freeDays" type="number" inputAlign="right" border="none" placeholder="请输入">
						</u-input>
					</u-form-item> -->

					<view style="height: 1rpx;background-color: #ebebec;margin-top: 10rpx;">
					</view>

				</view>

				<u-form-item v-if="6==addbean.plan.rentType" label="还款时间" :required="true" borderBottom @click="pickerShow(7)">
					<u-input v-model="addbean.orderCar.timeRepayment" inputAlign="right" placeholder="请选择" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

				<!-- <u-form-item  label="车辆已购保险" borderBottom @click="goSelInsurance">
					<u-input v-model="addbean.licenseDate" inputAlign="right" placeholder="查看已购保险" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item> -->

				<view v-if="1==addbean.plan.rentType||2==addbean.plan.rentType||3==addbean.plan.rentType||4==addbean.plan.rentType||5==addbean.plan.rentType" style="display: flex;flex-direction: column;">

					<u-form-item label="车辆已购保险" prop="">
					</u-form-item>

					<uni-data-checkbox multiple v-model="insuranceValueList" :localdata="insuranceList"
					:map="{
						'value':'value',
						'text':'value'
					}"
					></uni-data-checkbox>

					<view style="height: 1rpx;background-color: #ebebec;margin-top: 10rpx;">
					</view>
				</view>

				<view v-if="1==addbean.plan.rentType||2==addbean.plan.rentType||3==addbean.plan.rentType||4==addbean.plan.rentType||5==addbean.plan.rentType" style="display: flex;flex-direction: column;">

					<u-form-item label="租期选择" :required="true">
					</u-form-item>

					<view class="mradio" @click="addbean.plan.tenancyType=1">
						<u-icon :color="1==addbean.plan.tenancyType?'#1573FF':'#333'" :name="1==addbean.plan.tenancyType?'checkmark-circle-fill':'checkmark-circle'" size="18"></u-icon>
						<view style="display: flex;align-items: center;margin-left: 20rpx;">

							<text style="color: #a7a7a7;width: 200rpx;line-height: 40rpx;text-align: center;border: 1rpx solid #cecece;font-size: 26rpx;border-radius: 6rpx;"
								@click="pickerShow(4)">{{addbean.plan.timeStartRent==null||addbean.plan.timeStartRent==''?'开始时间':addbean.plan.timeStartRent}}</text>
							<text style="margin: 0 15rpx;color: #a7a7a7;">—</text>
							<text style="color: #a7a7a7;width: 200rpx;line-height: 40rpx;text-align: center;border: 1rpx solid #cecece;font-size: 26rpx;border-radius: 6rpx;"
								@click="pickerShow(5)">{{addbean.plan.timeFinishRent==null||addbean.plan.timeFinishRent==''?'结束时间':addbean.plan.timeFinishRent}}</text>

						</view>
					</view>

					<view class="mradio" style="margin-top: 10rpx;" @click="addbean.plan.tenancyType=2">
						<u-icon :color="2==addbean.plan.tenancyType?'#1573FF':'#333'" :name="2==addbean.plan.tenancyType?'checkmark-circle-fill':'checkmark-circle'" size="18"></u-icon>
						<text style="flex: 1;white-space: nowrap;">租期选择(月)</text>

						<view style="display: flex;align-items: center;" >
							<u-input v-model="addbean.plan.tenancy" inputAlign="right" placeholder="请输入租赁期限" type="number" border="none"></u-input>
						</view>

					</view>

					<view style="height: 1rpx;background-color: #ebebec;margin-top: 10rpx;">
					</view>

				</view>

				<u-form-item label="所属渠道商" borderBottom @click="goSelChannel">
					<u-input v-model="addbean.plan.channelName" inputAlign="right" placeholder="请选择渠道商" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

				<u-form-item label="渠道返利/元" borderBottom>
					<u-input v-model="addbean.plan.chlRebate" type="digit" inputAlign="right" placeholder="请输入" border="none"></u-input>
				</u-form-item>

				<u-form-item label="订单备注" borderBottom>
					<u-input v-model="addbean.orderCar.orderDesc" inputAlign="right" placeholder="请输入备注信息" border="none"></u-input>
				</u-form-item>

				<u-form-item>
					<view class="car-photo" style="padding: 20rpx 0; display: block;font-size: 30rpx;color: #333;">订单附件</view>
					<lr-upload ref="upload1" objType="27" tag="1" @on-change="uploadOnChange"></lr-upload>
				</u-form-item>

			</u-form>

		</view>

		<view class="item" style="padding: 20rpx 30rpx 0;margin-top: 10rpx;">

			<u-form :model="addbean" ref="uform" label-width="auto">

				<view style="height: 50rpx;display: flex;align-items: center;">
					<u-icon name="order" color="#1573FF" label="车辆信息" label-color="#333333"></u-icon>
				</view>

				<u-form-item label="选择车架号" :required="true" borderBottom @click="selVin">
					<u-input v-model="addbean.orderCar.vinNo" inputAlign="right" placeholder="选择车架号" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

				<u-form-item label="选择车牌号" :required="true" borderBottom @click="selVin">
					<u-input v-model="addbean.orderCar.carNo" inputAlign="right" placeholder="选择车牌号" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

				<u-form-item label="车辆归属" borderBottom>
					<u-input v-model="addbean.orderCar.deptName" inputAlign="right" disabled
						disabledColor="#ffffff" border="none" placeholder="自动获取"></u-input>
				</u-form-item>

				<u-form-item label="车辆仓库" borderBottom>
					<u-input v-model="addbean.orderCar.depotName" inputAlign="right" disabled
						disabledColor="#ffffff" border="none" placeholder="自动获取">
					</u-input>
				</u-form-item>

				<u-form-item label="随车物品" prop="">
				</u-form-item>

				<uni-data-checkbox multiple v-model="accessoryValueList" :localdata="checkboxList"
				:map="{
					'value':'value',
					'text':'value'
				}"
				></uni-data-checkbox>

				<u-form-item label="备注">
					<u-input v-model="addbean.orderCar.carDesc" inputAlign="right" placeholder="请输入备注" border="none"></u-input>
				</u-form-item>

				<u-form-item label="预计过户时间" v-if="false">
					<u-input v-model="addbean.licenseDate" inputAlign="right" placeholder="请选择预计过户时间" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

			</u-form>

		</view>

		<view class="item" style="padding: 20rpx 30rpx 0;margin-top: 10rpx;">

			<u-form :model="addbean" ref="uform" label-width="auto">

				<view style="height: 50rpx;display: flex;align-items: center;">
					<u-icon name="order" color="#1573FF" label="交车信息" label-color="#333333"></u-icon>
				</view>

				<u-form-item label="交车时间" :required="true" borderBottom @click="pickerShow(6)">
					<u-input v-model="addbean.orderCar.timeDelivery" inputAlign="right" placeholder="选择交车时间" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

				<u-form-item label="交车工作人员" borderBottom @click="selGiveMan">
					<u-input v-model="addbean.orderCar.deliveryOperationName" inputAlign="right" placeholder="选择交车工作人员" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

				<u-form-item label="交车备注" borderBottom>
					<u-input v-model="addbean.orderCar.deliveryDesc" inputAlign="right" placeholder="请输入备注" border="none"></u-input>
				</u-form-item>

				<u-form-item>
					<view class="car-photo" style="padding: 20rpx 0; display: block;font-size: 30rpx;color: #333;">交车附件</view>
					<lr-upload ref="upload2" objType="8" tag="2" @on-change="uploadOnChange"></lr-upload>
				</u-form-item>

				<u-form-item label="交车当前里程数/km" borderBottom>
					<u-input v-model="addbean.orderCar.deliveryMileage" type="digit" inputAlign="right" placeholder="请输入" border="none"></u-input>
				</u-form-item>

				<u-form-item label="下次保养公里数/km" borderBottom>
					<u-input v-model="addbean.orderCar.mileageNextMaintenance" type="digit" inputAlign="right" placeholder="请输入" border="none"></u-input>
				</u-form-item>

				<u-form-item label="下次保养时间" @click="pickerShow(8)">
					<u-input v-model="addbean.orderCar.mileageNextDate" inputAlign="right" placeholder="请选择" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

			</u-form>

		</view>

		<view class="item" style="padding: 20rpx 30rpx 0;margin-top: 10rpx;">

			<u-form :model="addbean" ref="uform" label-width="auto">

				<view style="height: 50rpx;display: flex;align-items: center;">
					<u-icon name="order" color="#1573FF" label="合同信息" label-color="#333333"></u-icon>
				</view>

				<u-form-item label="选择合同生成方式" @click="selContract">
					<u-input
					 :value="contractStr"
					 inputAlign="right" placeholder="请选择合同生成方式" disabled
						disabledColor="#ffffff" border="none"></u-input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>

			</u-form>

		</view>


		<view style="height: 100rpx;"></view>

		<view class="button-container">
			<button class="btn-item btn-left" @click="bottomClick(1)">暂存</button>
			<button class="btn-item btn-right" @click="bottomClick(2)">提交</button>
		</view>

		<!-- 还款方式 -->
		<u-picker :show="paymethodShow" :default-selector="[0]" :columns="paymethodList"
			keyName="value" @confirm="pickerConfim" @cancel="paymethodShow=false"></u-picker>

		<!-- 品牌车型 -->
		<u-picker :mode="mode" :show="carInfoShow" :default-selector="[0]" :columns="carInfoList"
			keyName="brandSeriesModel" @confirm="pickerConfim" @cancel="carInfoShow=false"></u-picker>

		<!-- 还款日 -->
		<u-picker :mode="mode" :show="payDayShow" :default-selector="[0]" :columns="paydayList"
			keyName="mValue" @confirm="pickerConfim" @cancel="payDayShow=false"></u-picker>

		<!-- 还款时间 -->
		<u-datetime-picker
			:show="payTimeShow"
			mode="date" @confirm="timeConfirm"
			@cancel="payTimeShow=false"></u-datetime-picker>

		<!-- 租期开始时间 -->
		<u-datetime-picker
			:show="rentStartShow"
			v-model="value1" :maxDate="value2"
			mode="date" @confirm="timeConfirm"
			@cancel="rentStartShow=false"></u-datetime-picker>

		<!-- 租期结束时间 -->
		<u-datetime-picker
			:show="rentEndShow"
			v-model="value2" :minDate="value1"
			mode="date" @confirm="timeConfirm"
			@cancel="rentEndShow=false"></u-datetime-picker>

		<!-- 交车时间 -->
		<u-datetime-picker
			:show="giveTimeShow"
			mode="date" @confirm="timeConfirm"
			@cancel="giveTimeShow=false"></u-datetime-picker>

		<!-- 下次保养时间 -->
		<u-datetime-picker
			:show="nextTimeShow"
			mode="date" @confirm="timeConfirm"
			@cancel="nextTimeShow=false"></u-datetime-picker>

		<!-- 车辆归属 -->
		<gljyDataPicker class="deptPicker" ref="picker" :idkey="'deptId'" :isSuper="true" namekey="deptName"
			:childrenkey="'subDeptList'" :title="'请选择'" :initList="deptList" @itemOnclick="itemOnclickDept">
		</gljyDataPicker>

	</view>
</template>

<script>
	import gljyDataPicker from "@/components/gljy-data-picker/gljy-data-picker.vue";
	import lrUpload from '@/components/global/lr-upload.vue'
  import {isVideo} from "@/common/calc";

	export default {
		components: {
			lrUpload,
			gljyDataPicker,
		},
		data() {
			return {
				value1:Number(new Date()),
				value2:Number(new Date())+12*30*24*3600*1000,
				contractStr:'',
				addbean: {
					contract:{
						contractType:0,
						timeFinish:'',
						timeStart:''
					},
					orderCar:{
						paymentDayType:1,
						timeRepayment:'',
						orderFileLst:[],
						id:'',
						code:'',
						orderId:'',
						carId:'',
						carNo:'',
						vinNo:'',
						deptId:'',
						deptName:'',
						depotId:'',
						depotName:'',
						cityId:'',
						cityName:'',
						mileage:'',
						electricQuantity:'',
						accessoryItemsName:'',
						accessoryItems:'',
						carDesc:'',
						orderDesc:'',
						deliveryOperationId:'',
						deliveryOperationName:'',
						deliveryMileage:'',
						mileageNextMaintenance:'',
						mileageNextDate:'',
						deliveryDesc:'',
						timeDelivery:'',
						timeTransferEstimated:'',
						deliveryFileLst:[],

					},
					plan:{
						paymentMethod:'',
						paymentMethodName:'',
						rentType:0,
						rentTypeName:'',
						brandSeriesModel:'',
						brandId:'',
						brandName:'',
						seriesId:'',
						seriesName:'',
						modelId:'',
						modelName:'',
						cashDeposit:'',
						downPayment:'',
						balancePayment:'',
						monthlyRent:'',
						repaymentMethods:'',
						financeCompanyName:'',
						chlRebate:'',
						freeDays:'',
						desc:'',
						insuranceItems:'',
						paymentDay:'',
						channelId:'',
						channelName:'',
						timeStartRent:'',
						timeFinishRent:'',
						tenancy:'',
						tenancyType:1,
						servicingFee:'',
						totalPrice:'',
						coverCharge:'',
						balancePaymentLst:[],

					},
					bpmChartDtoList:[],
					customFieldMap:{

					},
					lessorId:'',
					lessorName:'',
					customerId:'',
					customerType:'',
					customerName:'',
					customerAddr:'',
					customerTel:'',
				},
				//随车物品
				checkboxList: [],
				//已购保险
				insuranceList: [],
				value:[],
				intentData:{
				},
				querychoice:{},
				defaultOrderId:'',
				pickerType:0,
				//还款方式
				paymethodShow: false,
				paymethodList:[],
				//车辆归属
				deptList: [],
				//品牌车型
				carInfoShow: false,
				carInfoList: [],
				//还款日
				paydayList: [],
				payDayShow:false,
				payDayStr:'',
				balancestr:'',
				payTimeShow:false,
				rentStartShow:false,
				rentEndShow:false,
				giveTimeShow:false,
				nextTimeShow:false,
				insuranceValueList:[],
				accessoryValueList:[]
			}
		},
		methods: {
			getcontractStr(){
				if(2==this.addbean.contract.contractType){
					return uni.$u.test.isEmpty(this.addbean.contract.templateId)?'':'已选择根据订单自动生成合同'
				}else if(1==this.addbean.contract.contractType){
					return uni.$u.test.isEmpty(this.addbean.contract.code)?'':'已选择填写合同信息'
				}else{
					return ''
				}
			},

			selContract(){

				getApp().globalData.addOrderContract = this.addbean.contract

				uni.navigateTo({
					url:'/pagesB/contract/add-contract-type?noWorkFlow=true&type='+this.addbean.plan.rentType
				})
			},

			selLessor(){
				this.$refs.picker._show();
			},

			selCustomer(){
				uni.navigateTo({
					url:'/pages/customer/customer-center?type=select'
				})
			},
			addFinalFee(){

				var intentData = JSON.stringify(this.addbean.plan.balancePaymentLst);
				uni.navigateTo({
					url:'/pagesB/addorder/add-finalfee?balancePaymentLst=' + intentData
				})
			},

			bottomClick(type){

				switch(type){
					case 1:
						this.saveData(1)
					break
					case 2:
						if(uni.$u.test.isEmpty(this.defaultOrderId)){
							//新增
							this.saveData(2)
						}else{
							//编辑
							this.saveData(3)
						}
					break
				}
			},

			//1暂存   2新增提交   3编辑提交
			saveData(atype){
				this.addbean.plan.insuranceItems = this.insuranceValueList.join(',')
				this.addbean.orderCar.accessoryItemsName = this.accessoryValueList.join(',')

				let that = this

				console.log('this.addbean===>', this.addbean)

				if(2==atype||3==atype){
					if(uni.$u.test.isEmpty(this.addbean.lessorId)){
						this.$u.toast('请选择出租方')
						return
					}

					if(uni.$u.test.isEmpty(this.addbean.customerId)){
						this.$u.toast('请选择客户')
						return
					}

					if(uni.$u.test.isEmpty(this.addbean.plan.modelId)){
						this.$u.toast('请选择品牌/车系/车型')
						return
					}


					switch(this.addbean.plan.rentType){
						case '1':
						case '3':
						case '4':

							if(uni.$u.test.isEmpty(this.addbean.plan.cashDeposit)){
								this.$u.toast('请输入保证金')
								return
							}

							if(uni.$u.test.isEmpty(this.addbean.plan.monthlyRent)){
								this.$u.toast('请输入月租金')
								return
							}

							if(uni.$u.test.isEmpty(this.addbean.plan.paymentMethod)){
								this.$u.toast('请选择还款方式')
								return
							}

							if(!uni.$u.test.isEmpty(this.addbean.orderCar.paymentDayType)){
								if (2==this.addbean.orderCar.paymentDayType) {
									if (uni.$u.test.isEmpty(this.addbean.plan.paymentDay)) {
										this.$u.toast("请选择还款日");
										return;
									}
								}
							}else{
								this.$u.toast("请选择还款日类型");
								return;
							}

							if (1==this.addbean.plan.tenancyType) {
								//时间区间
								if (uni.$u.test.isEmpty(this.addbean.plan.timeStartRent) || uni.$u.test.isEmpty(this.addbean.plan.timeFinishRent)) {
									this.$u.toast("请选择租期时间区间");
									return;
								}
							} else if (2==this.addbean.plan.tenancyType) {
								//输入租期
								if (uni.$u.test.isEmpty(this.addbean.plan.tenancy)) {
									this.$u.toast("请输入租期期限");
									return;
								}
							} else {
								this.$u.toast("请选择租期");
								return;
							}

							break
						case '2':
							if(uni.$u.test.isEmpty(this.addbean.plan.servicingFee)){
								this.$u.toast('请输入整备费')
								return
							}
							if(uni.$u.test.isEmpty(this.addbean.plan.monthlyRent)){
								this.$u.toast('请输入月租金')
								return
							}
							if(uni.$u.test.isEmpty(this.addbean.plan.paymentMethod)){
								this.$u.toast('请选择还款方式')
								return
							}

							if(!uni.$u.test.isEmpty(this.addbean.orderCar.paymentDayType)){
								if (2==this.addbean.orderCar.paymentDayType) {
									if (uni.$u.test.isEmpty(this.addbean.plan.paymentDay)) {
										this.$u.toast("请选择还款日");
										return;
									}
								}
							}else{
								this.$u.toast("请选择还款日类型");
								return;
							}

							if (1==this.addbean.plan.tenancyType) {
								//时间区间
								if (uni.$u.test.isEmpty(this.addbean.plan.timeStartRent) || uni.$u.test.isEmpty(this.addbean.plan.timeFinishRent)) {
									this.$u.toast("请选择租期时间区间");
									return;
								}
							} else if (2==this.addbean.plan.tenancyType) {
								//输入租期
								if (uni.$u.test.isEmpty(this.addbean.plan.tenancy)) {
									this.$u.toast("请输入租期期限");
									return;
								}
							} else {
								this.$u.toast("请选择租期");
								return;
							}

							break

						case '5':
							if(uni.$u.test.isEmpty(this.addbean.plan.downPayment)){
								this.$u.toast('请输入首付款')
								return
							}
							if(uni.$u.test.isEmpty(this.addbean.plan.monthlyRent)){
								this.$u.toast('请输入月租金')
								return
							}
							if (1==this.addbean.plan.tenancyType) {
								//时间区间
								if (uni.$u.test.isEmpty(this.addbean.plan.timeStartRent) || uni.$u.test.isEmpty(this.addbean.plan.timeFinishRent)) {
									this.$u.toast("请选择租期时间区间");
									return;
								}
							} else if (2==this.addbean.plan.tenancyType) {
								//输入租期
								if (uni.$u.test.isEmpty(this.addbean.plan.tenancy)) {
									this.$u.toast("请输入租期期限");
									return;
								}
							} else {
								this.$u.toast("请选择租期");
								return;
							}
							break
						case '6':
							if(uni.$u.test.isEmpty(this.addbean.plan.totalPrice)){
								this.$u.toast('请输入车辆总单价')
								return
							}
							if(uni.$u.test.isEmpty(this.addbean.orderCar.timeRepayment)){
								this.$u.toast('请选择还款时间')
								return
							}
							break
					}

					if(uni.$u.test.isEmpty(this.addbean.orderCar.vinNo)){
						this.$u.toast('请选择车辆')
						return
					}

					if(uni.$u.test.isEmpty(this.addbean.orderCar.timeDelivery)){
						this.$u.toast('请选择交车时间')
						return
					}

				}

        let addbean = uni.$u.deepClone(that.addbean);
        addbean.plan.monthlyRent = Number(that.addbean.plan.monthlyRent).add(that.addbean.plan.coverCharge||0)

				uni.showModal({
					content: '确定提交吗?',
					success(res) {
						if (res.confirm) {
              uni.showLoading()

							if(1==atype){
								that.$u.api.orderTemporarystorage(addbean).then(res=>{
                  uni.hideLoading()
									uni.$emit('refreshOrder', true)
									that.$u.toast('提交成功')

									setTimeout(()=>{
										uni.navigateBack()
									}, 1000)
								}).catch(e=>{
                  uni.hideLoading()
                })
							}else if(2==atype){
								that.$u.api.orderAdd(addbean).then(res=>{
                  uni.hideLoading()
									uni.$emit('refreshOrder', true)
									that.$u.toast('提交成功')
									setTimeout(()=>{
										uni.navigateBack()
									}, 1000)
								}).catch(e=>{
                  uni.hideLoading()
                })
							}else if(3==atype){
								that.$u.api.orderEdit(addbean).then(res=>{
                  uni.hideLoading()
									uni.$emit('refreshOrder', true)
									that.$u.toast('提交成功')
									setTimeout(()=>{
										uni.navigateBack()
									}, 1000)
								}).catch(e=>{
                  uni.hideLoading()
                })
							}

						}
					}
				})

			},

			goSelChannel(){
				uni.navigateTo({
					url: '/pagesA/channel/sel-channel?type=2'
				})
			},

			selVin(){
				if(uni.$u.test.isEmpty(this.addbean.lessorId)){
					this.$u.toast('请选择出租方')
					return
				}

				if(uni.$u.test.isEmpty(this.addbean.plan.modelId)){
					this.$u.toast('请选择品牌/车型/车系')
					return
				}

				uni.navigateTo({
					url:'/pages/car/allocation/car-carlist?modelId='+this.addbean.plan.modelId+'&depotId='+this.addbean.orderCar.depotId+'&deptId='+this.addbean.lessorId+'&type=10'
				})

			},

			selGiveMan(){
				uni.navigateTo({
					url:'/pages/customer/buss_owner_list'
				})
			},

			//图片上传成功回调
			uploadOnChange(tag, resultList, resultObjList) {
				console.log(tag, resultList, resultObjList);
				switch (tag) {
					case '1': //订单附件

						this.addbean.orderCar.orderFileLst = resultObjList;
						break

					case '2': //交车附件

						this.addbean.orderCar.deliveryFileLst = resultObjList;
						break


				}
			},

			//车辆归属选择回调事件
			itemOnclickDept(res) {

				if(res.deptId!=this.addbean.lessorId){
					//重置其他条件
					this.addbean.orderCar.carId=''
					this.addbean.orderCar.carNo=''
					this.addbean.orderCar.vinNo=''
					this.addbean.orderCar.deptId=''
					this.addbean.orderCar.deptName=''
					this.addbean.orderCar.depotId=''
					this.addbean.orderCar.depotName=''
					this.addbean.orderCar.cityId=''
					this.addbean.orderCar.cityName=''
					this.accessoryValueList = []

				}

				this.addbean.lessorName = res.deptName;
				this.addbean.lessorId = res.deptId;

				console.log(this.addbean.lessorName);
			},

			//picker是否显示
			pickerShow(type) {
				switch (type) {
					case 1:
						this.paymethodShow = true;
						break
					case 2:
						this.carInfoShow = true;
						break
					case 3:
						this.payDayShow = true;
						break
					case 4:
						this.rentStartShow = true;
						break
					case 5:
						this.rentEndShow = true;
						break
					case 6:
						this.giveTimeShow = true;
						break
					case 7:
						this.payTimeShow = true;
						break
					case 8:
						this.nextTimeShow = true;
						break
				}
				this.pickerType = type;
			},

			timeConfirm(e){
				let timeStr = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');

				switch (this.pickerType) {
					case 4: //租期开始时间
						this.rentStartShow = false;
						this.addbean.plan.timeStartRent = timeStr;
						break
					case 5: //租期结束时间
						this.rentEndShow = false;
						this.addbean.plan.timeFinishRent = timeStr;
						break
					case 6: //交车时间
						this.giveTimeShow = false;
						this.addbean.orderCar.timeDelivery = timeStr;
						break
					case 7: //还款时间
						this.payTimeShow = false;
						this.addbean.orderCar.timeRepayment = timeStr;
						break
					case 8: //下次保养时间
						this.nextTimeShow = false;
						this.addbean.orderCar.mileageNextDate = timeStr;
						break
				}
			},

			//picker回调函数
			pickerConfim(e) {
				switch (this.pickerType) {
					case 1: //还款方式
						this.paymethodShow = false;
						// let carInfoObjc = this.carInfoList[index];
						let paymethodObjc = e.value[0];

						this.addbean.plan.paymentMethod = paymethodObjc.code;
						this.addbean.plan.paymentMethodName = paymethodObjc.value;

						break

					case 2: //车辆
						this.carInfoShow = false;
						// let carInfoObjc = this.carInfoList[index];
						let carInfoObjc = e.value[0];

						if(carInfoObjc.modelId != this.addbean.plan.modelId){
							this.addbean.orderCar.carId=''
							this.addbean.orderCar.carNo=''
							this.addbean.orderCar.vinNo=''
							this.addbean.orderCar.deptId=''
							this.addbean.orderCar.deptName=''
							this.addbean.orderCar.depotId=''
							this.addbean.orderCar.depotName=''
							this.addbean.orderCar.cityId=''
							this.addbean.orderCar.cityName=''
							this.accessoryValueList = []
						}


						this.addbean.plan.brandId = carInfoObjc.brandId;
						this.addbean.plan.brandName = carInfoObjc.brandName;
						this.addbean.plan.seriesId = carInfoObjc.seriesId;
						this.addbean.plan.seriesName = carInfoObjc.seriesName;
						this.addbean.plan.modelId = carInfoObjc.modelId;
						this.addbean.plan.modelName = carInfoObjc.modelName;
						this.addbean.plan.brandSeriesModel = carInfoObjc.brandSeriesModel;

						break

					case 3: //还款日
						this.payDayShow = false;

						this.addbean.plan.paymentDay = e.value[0].code;
						this.payDayStr = e.value[0].mValue;
						break

					case 4: //有无侧门
						this.carSideShow = false;
						// let sideDoorObjc = this.sideList[index];
						let sideDoorObjc = e.value[0];
						this.vehicle.sideDoor = sideDoorObjc.code;
						this.vehicle.sideDoorStr = sideDoorObjc.code == 1 ? '有' : '无';
						break

					case 5: //车辆仓库
						this.carWarehouseShow = false;
						// let warehouseObjc = this.carWarehouseList[index];
						let warehouseObjc = e.value[0];
						this.vehicle.depotName = warehouseObjc.warehouseName;
						this.vehicle.depotId = warehouseObjc.warehouseId;
						break
				}
			},


		},
		onLoad(op) {
			this.intentData = getApp().globalData.addOrderIntentData;
			this.querychoice = this.$store.state.params.getCarCommon;
			this.checkboxList = this.querychoice.accessoryItem;
			this.insuranceList = this.querychoice.vehicleInsurance;
			this.carInfoList = [this.$store.state.params.brandseriesmodel];

			getApp().globalData.addOrderIntentData = {}


			this.defaultOrderId = op.orderId;

			if(!uni.$u.test.isEmpty(this.intentData)){

				this.addbean.plan.rentTypeName = this.intentData.value
				this.addbean.plan.rentType = this.intentData.code
			}

			if(!uni.$u.test.isEmpty(this.querychoice)){

				this.paymethodList = [this.querychoice.payMethod]
				let plist = this.querychoice.monthlyRentPaymentDate.map(item=>{
					item.mValue = `每月${item.value}号`
					return item
				})
				this.paydayList = [plist]
			}

			this.$u.api.getCommonDeptlist({
				type: '2'
			}).then(res => {
				this.deptList = res;
			})

			uni.$on('selectCustomer', res=>{
				console.log('选择了客户', res);

				this.addbean.customerId = res.customerId
				this.addbean.customerType = res.customerType
				this.addbean.customerName = res.customerName
				this.addbean.customerAddr = res.address
				this.addbean.customerTel = res.contactMobile
			})

			//添加尾款了
			uni.$on('addFinal', res=>{

				this.addbean.plan.balancePaymentLst = res;
				this.balancestr = !uni.$u.test.isEmpty(this.addbean.plan.balancePaymentLst)?'已添加尾款':''

			})

			//渠道商选择后的回调
			uni.$on('selChannel', res => {
				//收到选择的渠道商了
				this.addbean.plan.channelId = res.channelId
				this.addbean.plan.channelName = res.channelName
			})

			//交车工作人员选择了
			uni.$on('getRes', res => {
				//收到选择的渠道商了
				this.addbean.orderCar.deliveryOperationId = res.userId
				this.addbean.orderCar.deliveryOperationName = res.username
			})

			uni.$on('addcontract-bean', res=>{
				//收到合同了
				this.addbean.contract = res

				this.contractStr = this.getcontractStr()
			})

			//选车了
			uni.$on('selCar', res => {

				console.log('收到了车辆', res);

				if(res.vinNo!=this.addbean.orderCar.vinNo){
					//重置其他条件
					if(!uni.$u.test.isEmpty(res.accessoryItemsName)){

						this.accessoryValueList = res.accessoryItemsName.split(',')
					}

				}


				this.addbean.orderCar.carId = res.carId
				this.addbean.orderCar.carNo = res.carNo
				this.addbean.orderCar.vinNo = res.vinNo
				this.addbean.orderCar.deptId = res.deptId
				this.addbean.orderCar.deptName = res.deptName
				this.addbean.orderCar.depotId = res.depotId
				this.addbean.orderCar.depotName = res.depotName
				this.addbean.orderCar.cityId = res.cityId
				this.addbean.orderCar.cityName = res.cityName
			})

			if(!uni.$u.test.isEmpty(this.defaultOrderId)){
				//获取老数据
				uni.setNavigationBarTitle({
					title:'编辑订单信息'
				})

				this.$u.api.orderInfo({
					id:this.defaultOrderId
				}).then(res=>{
					this.addbean = res

          this.addbean.plan.monthlyRent = Number(this.addbean.plan.monthlyRent).sub(this.addbean.plan.coverCharge||0)

					//1经租  2以租代购  3展示车  4试驾车  5融租  6直购
					this.addbean.plan.rentTypeName = 1==this.addbean.plan.rentType ? "经租" :
									2==this.addbean.plan.rentType ? "以租代购" :
											3==this.addbean.plan.rentType ? "展示车" :
													4==this.addbean.plan.rentType ? "试驾车" :
															5==this.addbean.plan.rentType ? "融租" :
																	6==this.addbean.plan.rentType ? "直购" :
																	''

					if(!uni.$u.test.isEmpty(this.addbean.plan.brandName)
					&& !uni.$u.test.isEmpty(this.addbean.plan.seriesName)
					&& !uni.$u.test.isEmpty(this.addbean.plan.modelName)){
						this.addbean.plan.brandSeriesModel = this.addbean.plan.brandName+'/'+this.addbean.plan.seriesName+'/'+this.addbean.plan.modelName
					}

					this.balancestr = !uni.$u.test.isEmpty(this.addbean.plan.balancePaymentLst)?'已添加尾款':''

					this.addbean.plan.paymentMethodName = 1==this.addbean.plan.paymentMethod?'月付':
														2==this.addbean.plan.paymentMethod?'两月付':
														3==this.addbean.plan.paymentMethod?'季度':
														4==this.addbean.plan.paymentMethod?'年付':
														5==this.addbean.plan.paymentMethod?'一次性结清':
														7==this.addbean.plan.paymentMethod?'日付':
														8==this.addbean.plan.paymentMethod?'周付':
														''

					if(!uni.$u.test.isEmpty(this.addbean.plan.paymentDay)){
						this.payDayStr = `每月${this.addbean.plan.paymentDay}号`
					}

					if(!uni.$u.test.isEmpty(this.addbean.plan.insuranceItems)){
						this.insuranceValueList = this.addbean.plan.insuranceItems.split(',')
					}

					if(!uni.$u.test.isEmpty(this.addbean.orderCar.accessoryItemsName)){
						this.accessoryValueList = this.addbean.orderCar.accessoryItemsName.split(',')
					}

					let that = this;

					if(!uni.$u.test.isEmpty(this.addbean.orderCar.orderFileLst)){

						this.$refs.upload1.fileList1=this.addbean.orderCar.orderFileLst.filter(item => {
              return 1== item.type_file||1==item.typeFile
            }).map(item=>{
								return {
                  ...item,
									message: "",
									size: 52363,
									status: "success",
									thumb: that.baseImgUrl()+item.url,
									type: isVideo(item.url),
									url: item.url
								}
						})
					}

					if(!uni.$u.test.isEmpty(this.addbean.orderCar.deliveryFileLst)){

						this.$refs.upload2.fileList1=this.addbean.orderCar.deliveryFileLst.filter(item => {
              return 1== item.type_file||1==item.typeFile
            }).map(item=>{
								return {
                  ...item,
									message: "",
									size: 52363,
									status: "success",
									thumb: that.baseImgUrl()+item.url,
									type: isVideo(item.url),
									url: item.url
								}
						})
					}

					this.contractStr = this.getcontractStr()



				})

			}else{
				uni.setNavigationBarTitle({
					title:'新增车辆订单'
				})
			}

		}
	}
</script>

<style lang="scss" scoped>

	.p-content{
		display: flex;
		flex-direction: column;
	}

	.u-form {
		margin: 10px;
		padding: 22rpx;
		background-color: white;
	}

	.u-input {
		font-size: 24rpx;
	}

	.btn-left {
		background-color: $xz-bgColor-yellow;
	}

	.btn-right {
		background-color: $xz-bgColor-blue;
	}

	.mradio{
		display: flex;
		align-items: center;

		text{
			font-size: 30rpx;
			color: #666;
			margin-left: 10rpx;
		}
	}

	.deptPicker {
		position: fixed;
		z-index: 9999;
	}

</style>
